package acm.pta13;

import java.io.*;
import java.util.*;


class Test {
    static StreamTokenizer sc = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    //快写
    static PrintWriter out = new PrintWriter(System.out);

    //快读
    static int ini() throws IOException {
        sc.nextToken();
        return (int) sc.nval;
    }

    static LinkedList<Integer> result;     //最终的结果
    static ArrayList<LinkedList<Integer>> edges;    //邻接表来存储变异关系
    static LinkedList<Integer> temp;   //临时存储（过程存储）

    public static void main(String[] args) throws IOException {
        int n = ini();
        result = new LinkedList<>();
        edges = new ArrayList<>();
        temp= new LinkedList<>();
        boolean[] visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            edges.add(new LinkedList<>());  //创建邻接表
        }

        for (int i = 0; i < n; i++) {
            int k = ini();
            for (int j = 0; j < k; j++) {
                int thisNum = ini();
                visited[thisNum] = true;    //对出现过的节点做标记，表明它不是根节点
                edges.get(i).add(thisNum);
            }
            Collections.sort(edges.get(i));     //每次放完孩子都需要排序，以求得最小的编号
//            System.out.println(edges.get(i));
        }

        for (int i = 0; i < n; i++) {
            if (visited[i] == false) {  //找到根节点
                temp.add(i);
                bfs(i); //从根节点开始搜索
                break;
            }
        }

        out.println(result.size());

        for (int i = 0; i < result.size(); i++) {
            if (i == 0) {
                out.print(result.get(i));
            } else {
                out.print(" " + result.get(i));
            }
        }
        out.flush();
        out.close();
    }

    private static void bfs(int index) {
        if (temp.size() > result.size()) {  //如果temp的长度>result的长度，则更新result
            result = new LinkedList<>(temp);
        }

        for (int i = 0; i < edges.get(index).size(); i++) {     //标号为index的孩子节点
            temp.add(edges.get(index).get(i));  //先将孩子节点入temp
            bfs(edges.get(index).get(i));   //对孩子节点进行深度搜索
            temp.removeLast();  //回溯回溯回溯！
        }
    }
}


